package com.cwd.arm.domain.util;

import com.cwd.arm.domain.entity.ProjectEntity;
import com.cwd.arm.domain.entity.ReceiveNodeEntity;
import com.cwd.arm.domain.entity.base.MsgReEntity;
import com.cwd.arm.infrastructure.po.ProjectPo;
import com.cwd.arm.infrastructure.po.ReceiveNodePo;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by yan on 22-2-19.
 */
public class PoToEntityUtil {

    public static MsgReEntity poToEntity(ProjectPo po){
        ProjectEntity entity = new ProjectEntity();
        BeanUtils.copyProperties(po,entity);
        return entity;
    }

    public static List<MsgReEntity> poToProjectEntityList(List<ProjectPo> poList){
        return poList.stream().map(po->poToEntity(po)).collect(Collectors.toList());
    }

    public static MsgReEntity poToEntity(ReceiveNodePo po,String projectName){
        ReceiveNodeEntity entity = (ReceiveNodeEntity)poToEntity(po);
        entity.setProjectName(projectName);
        return entity;
    }

    public static MsgReEntity poToEntity(ReceiveNodePo po){
        ReceiveNodeEntity entity = new ReceiveNodeEntity();
        BeanUtils.copyProperties(po,entity);
        return entity;
    }

    public static List<MsgReEntity> poToReceiveNodeEntityList(List<ReceiveNodePo> poList,String projectName){
        return poList.stream().map(po->poToEntity(po,projectName)).collect(Collectors.toList());
    }
}
